//
//  TransactionDetailsViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 2016/11/8.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "TransactionDetailsViewController.h"
#import "MallRequestManager.h"
#import "PaymenHistoryViewController.h"
@interface TransactionDetailsViewController ()
@property (nonatomic,strong)IBOutlet UILabel *moneyLabel;
@property (nonatomic,strong)IBOutlet UILabel *typeLabel;
@property (nonatomic,strong)IBOutlet UILabel *dateLabel;
@property (nonatomic,strong)IBOutlet UILabel *payTypeLabel		;
@property (nonatomic,strong)IBOutlet UILabel *daoqiDateLabel;
@property (nonatomic,strong)IBOutlet UILabel *serialNumLabel;
@property (nonatomic,strong)IBOutlet UIImageView *imgView;
@property (nonatomic,strong)NSMutableDictionary *dataDic;
@end

@implementation TransactionDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"交易详情";
    [self showNavgationWithLeftItemWithTitle:@"返回"];
    [self requestData];
}
- (void)requestData
    {
        NSMutableDictionary *params = [NSMutableDictionary new];
        //如果用户没有登陆则用户编号为0
        NSString *orderId = self.orderId;
        int num = [orderId intValue];
        NSNumber *userIdNum = [NSNumber numberWithInt:num];
        [params setObject:userIdNum forKey:@"orderid"];
        [SVProgressHUD showWithStatus:@"加载中..."];
        //缴费详情接口
        [MallRequestManager post:@"Charge/fee_details" RequestParams:params FinishBlock:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                [SVProgressHUD showErrorWithStatus:@"数据请求错误"];
            }
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            if (dic!=nil) {
                if ([dic.allKeys containsObject:@"result"]) {
                    self.dataDic = [dic objectForKey:@"result"];
                }
            }
            [self performSelectorOnMainThread:@selector(reloadUI) withObject:nil waitUntilDone:YES];
        }];
    }
- (void)reloadUI
{
        [SVProgressHUD dismiss];
       self.moneyLabel.text = [NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"payamount"]];
    self.typeLabel.text= [NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"title"]];
        self.dateLabel.text = [NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"paytime"]];
         self.payTypeLabel.text = [NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"pay_type"]];
       self.serialNumLabel.text = [NSString stringWithFormat:@"%@", [self.dataDic objectForKey:@"paynumber"]];
         self.daoqiDateLabel.text = [self.dataDic objectForKey:@"desc"];
        if ([[self.dataDic objectForKey:@"type"]isEqualToString:@"1"]) {
             [self.imgView setImage:[UIImage imageNamed:@"服务费续费"]];
        }else
        {
            [self.imgView setImage:[UIImage imageNamed:@"漫游费缴纳"]];
        }
}
-(void)backTo
{
    [super backTo];
    if ([self.flag isEqualToString:@"1"]) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    if ([self.flag isEqualToString:@"2"]) {
        PaymenHistoryViewController *paymenHistoryVC = [[UIStoryboard storyboardWithName:@"PersonalViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"PaymenHistoryViewController"];
        [self.navigationController popToViewController:paymenHistoryVC animated:YES];
    }
}
@end
